class Solution {

public:
    int minSubArrayLen(int target, vector<int>& nums) {
        int result = 0;
        int i = 0, j = 0;
        int count = 0;
        int len = nums.size();
        while (j < len) {
            if (result < target)
                result += nums[j];
            while (result >= target) {
                if (count == 0)
                    count = j - i + 1;
                else {
                    if (j - i + 1 < count)
                        count = j - i + 1;
                }
                if (i <= j) {
                    result -= nums[i];
                    i++;
                }
            }
            j++;
        }
        return count;

    }
};